const getRow = rowIndex => {
    let res = [[1]]
    if (rowIndex == 0) return res;
    res.push([1, 1])
    if (rowIndex == 1) return res[1];
    for (let i = 2; i <= rowIndex; i++) {
        let arr = new Array(i + 1).fill(1)
        for (let j = 1; j < arr.length - 1; j++) {
            arr[j] = res[i - 1][j - 1] + res[i - 1][j]
        }
        res.push(arr)
    }
    return res[rowIndex]
}

console.log(getRow(2));